package org.ling.xuan.action.copy;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import org.jetbrains.annotations.NotNull;
import org.ling.xuan.util.LoggerUtil;
import org.ling.xuan.util.LxOptional;
import org.ling.xuan.util.LxStrUtil;

import java.awt.*;
import java.awt.datatransfer.StringSelection;

/**
 * lx复制本地路径
 *
 * @author liting50684
 * @date 2023/08/21
 */
public class LxCopyLocalPathAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        String text = LxStrUtil.unionPath(LxOptional.of(e, c -> c.getDataContext().getData(CommonDataKeys.VIRTUAL_FILE).getPath()).orElse(""));
        StringSelection selection = new StringSelection(text);
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
        LoggerUtil.log(e.getProject(), "copy success:{}", text);
    }

}
